package com.oocl.client.vibration;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.oocl.client.ui.BaseFrame;

/**
 * 屏幕振动器
 * 
 * @author WUJA13
 * 
 */
public class ScreenVibrator {

	private Timer timer;

	public ScreenVibrator() {
	}

	// /开始振动某个窗口（上 --> 下 --> 左 --> 右）
	public void startVibrate(final BaseFrame frame) {
		timer = new Timer();
		timer.schedule(new TimerTask() {
			int j = 0;
			 int curPosX = frame.getX();
			 int curPosY = frame.getY();

			@Override
			public void run() {
				if (j <= 12) {
					if (j%4==0) {
						frame.setLocation(curPosX, curPosY-5);
					} else if (j%4==1) {
						frame.setLocation(curPosX+5, curPosY);
					} else if (j%4==2) {
						frame.setLocation(curPosX, curPosY+5);
					} else if (j%4==3) {
						frame.setLocation(curPosX-5, curPosY);
					}
				}
				j++;
				if (j >= 12) {
					j = 0;
					timer.cancel();
				}
			}
		}, 30, 30);
	}

}
